<template>
	<view>
		<view>
			<u-swiper :list="swiper_list" :effect3d="true"></u-swiper>
		</view>
		<view>
			<u-grid :col="4">
				<u-grid-item @click="events_form">
					<u-icon name="list-dot" :size="46"></u-icon>
					<view class="grid-text">事件上报</view>
				</u-grid-item>
				<u-grid-item @click="renting_index">
					<u-icon name="home" :size="46"></u-icon>
					<view class="grid-text">出租房</view>
				</u-grid-item>
				<u-grid-item @click="notice_index">
					<u-icon name="bell" :size="46"></u-icon>
					<view class="grid-text">社区公告</view>
				</u-grid-item>
				<u-grid-item @click="test_index">
					<u-icon name="bell" :size="46"></u-icon>
					<view class="grid-text">测试</view>
				</u-grid-item>
			</u-grid>
		</view>
		<view  class="layout-list">
			<u-section class="section-text" title="社区公告" sub-title="查看更多" @click="notice_index"></u-section>
			<!--社区公告列表-->
			<view v-if="notice_list!==null && notice_list.length==0">
				<u-empty text="无数据" mode="list"></u-empty>
			</view>
			<u-cell-group>
				<u-cell-item icon="bell" v-for="(item, index) in notice_list" :key="index" :title="item.title" :value="item.date" @click="to_notice_form(item)"></u-cell-item>
			</u-cell-group>
		</view>
		<view class="layout-list">
			<u-section class="section-text" title="上报事件" sub-title="查看更多" @click="events_index"></u-section>
			<view v-if="events_list!==null && events_list.length==0">
				<u-empty text="无数据" mode="list"></u-empty>
			</view>
			<u-cell-group>
				<u-cell-item icon="list-dot" v-for="(item, index) in events_list" :key="index" :title="item.title" :value="item.date" @click="to_event_form(item)"></u-cell-item>
			</u-cell-group>
		</view>
		<view class="layout-list">
			<u-section class="section-text" title="待办事项" :right="false"></u-section>
			<u-empty text="无数据" mode="list"></u-empty>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiper_list: [],
				//公告列表
				notice_list: [],
				//事件列表
				events_list: []
			}
		},
		onLoad() {
			this.loadSwiperList();
			this.loadNoticeList();
			this.loadEventsList();

		},
		methods: {
			loadSwiperList: function() {
				let _self = this;
				_self.$serverData.app_swiper_list(_self, null, function(res) {
					_self.swiper_list = res.data.data;
				});
			},
			loadNoticeList: function() {
				let _self = this;
				_self.$serverData.app_notice_list(_self, null, function(res) {
					_self.notice_list = res.data.data;
				});
			},
			loadEventsList: function() {
				let _self = this;
				_self.$serverData.app_events_list(_self, null, function(res) {
					_self.events_list = res.data.data;
				});
			},

			events_form: function() {
				//跳转事件上报
				this.$routerTo.page('../events/events_form');
			},
			events_index: function() {
				//跳转事件列表
				this.$routerTo.page('../events/events_list');
			},
			renting_index: function() {
				//跳转出租房
				this.$routerTo.page('../renting/index');
			},
			notice_index: function() {
				//跳转社区公告
				this.$routerTo.page('../notice/notice_list');
			},
			test_index: function() {
				//跳转至测试页面
				this.$routerTo.page('../test/test_index');
			},
			//跳转至公告详情页面
			to_notice_form: function(item){
				this.$routerTo.page('../notice/notice_form?item='+encodeURIComponent(JSON.stringify(item)))
			},
			to_event_form: function(item){
				this.$routerTo.page('../events/events_form?item='+encodeURIComponent(JSON.stringify(item)))
			},


		}
	}
</script>

<style lang="scss" scoped>
	.layout-list{
		margin-top: 50rpx;
		margin-left: 30rpx;
		margin-right: 30rpx;
	}
	
</style>
